# 发起请求的必备要素：
# 请求头、请求体、请求方式、ip地址、端口号
import requests
# 发起登录请求，已经符合了必备要素：请求头、请求体、请求方式、ip地址、端口号
project_url = "http://47.97.110.120:8899"

response = requests.post(url = project_url + "/adminapi/login",
              json={"account":"admin","pwd":"123456","key":"6618e4403150d","captchaType":"blockPuzzle","captchaVerification":""})
# 响应
# print(response.status_code) # 查看响应状态码
# print(response.text) # 返回文本格式，python的原始对象：<class 'str'>
# print(response.json()) # 返回响应报文：json格式   python的原始对象：<class 'dict'>
# print(response.url) # 打印请求地址：http://47.97.110.120:8899/adminapi/login
# print(response.content) # 返回进制格式，前面带个b
# print(response.encoding) # 返回编码：utf-8
# print(response.cookies) # 返回cookies
# print(response.elapsed.microseconds) # 获取响应时间
# print(response.headers) # 获取响应头
"""
status_code = response.json()['status']               # 提取状态码
message = response.json()['msg']               # 提取meg
print(status_code)
print(message)
token = response.json()['data']['token'] # 提取token
print(token)
"""
token = response.json()['data']['token'] # 提取token
# 查询用户分组
response1 = requests.get(url = project_url + "/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-zation":"Bearer " + str(token)})

# 查询的响应结果
# id = response1.json()['data']['list']['id']           # 提取
# id_list = []
# for i in response1.json()['data']['list']:
#     id_list.append(i['id'])
# print(id_list)


# requests 上传图片
"""
url = "https://graph.baidu.com/upload"
files = {
    "image":("333.jpg",open(r'C:\Users\PC\Desktop\333.jpg','rb'),"image/jpeg"),
}
reponse = requests.post(url,files=files)
print(reponse.json())
"""



